# coding: utf-8
from django.db import models
from django import forms
from django.forms import ModelForm

# Create your models here.

class Good(models.Model):
    '''
    Товары в магазине
    '''
    name=models.CharField(max_length=100)
    type=models.ManyToManyField('Type')
    cost=models.PositiveIntegerField()
    text=models.TextField()
    #picture=models.ImageFiels(upload_to='../pictures')
    number=models.PositiveIntegerField()
    other=models.ManyToManyField('Other', null=True, blank=True)
    '''
    def __unicode__(self):
        return self.name
    '''
class Type(models.Model):
    '''
    Тип товара
    '''
    tag=models.CharField(max_length=100)
    parent=models.ForeignKey('self', blank=True,  null=True)
    def __unicode__(self):
        return self.tag

class Other(models.Model):
    '''
    Дополнительное поле к товару
    '''
    name=models.CharField(max_length=100)
    data=models.TextField()
    def __unicode__(self):
        return self.name
    
class GoodBasket(models.Model):
    '''
    Товары для корзины
    '''
    good=models.ForeignKey('Good')
    number=models.PositiveIntegerField()
    preorder=models.BooleanField()
    basket=models.ForeignKey('Basket')
    def __unicode__(self):
        return self.good.name

class Basket(models.Model):
    '''
    Корзина
    '''
    name=models.CharField(max_length=100, blank=True, null=True)
    adress=models.CharField(max_length=100, blank=True, null=True)
    #telephone=models.CharFields(max_length=100, blank=True, null=True)
    #email=models.CharFields(max_length=100, blank=True, null=True)
    comment=models.TextField(blank=True, null=True)
    call=models.BooleanField()
    end=models.BooleanField()
    admin_comment=models.TextField(blank=True, null=True)
    def __unicode__(self):
        return str(self.pk)

class GoodAddForm(forms.Form):
    number=forms.IntegerField()

class BasketForm(ModelForm):
    class Meta:
        model=Basket
        fields=('name','adress', 'comment')
